import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/a_elder/models/elder_entity.dart';
import 'package:ls_work/common/common.dart';
import 'package:flustars_flutter3/flustars_flutter3.dart' as FlutterStars;
import 'package:ls_work/message/message_config.dart';
import 'package:ls_work/net/post_request.dart';
import 'package:ls_work/net/response/medical_record_list.dart';
import 'package:ls_work/net/response/response_data.dart';
import 'package:ls_work/ui/medical/add_medical_page.dart';
import 'package:ls_work/util/request_url_utils.dart';

class MedicalRecordViewModel extends BaseListViewModel<MedicalRecordList> {
  final ElderInfo? info;
  MedicalRecordViewModel(BuildContext context,{this.info}) : super(context);

  var branchId = FlutterStars.SpUtil.getString(Constant.branchId);

  var cityId = "";

  @override
  Future<List<MedicalRecordList>> requestListData() async {
    // if(branchId.isNullOrEmpty()){
    //   branchId = RequestUrlUtils.branchId;
    // }
    var map = await PostRequest.medicalRecord(branchId, cityId);
    var bean = ResponseData.fromJson(map,listBuilder: (i)=>MedicalRecordList.fromJson(i));
    if("0"==bean.code){
      return bean.data?.rows??[];
    }else{
      throw (bean.msg??"");
    }
  }

  @override
  void onCreated() {
    super.onCreated();
    requestRefresh();
  }

  void toAddSign() {
     Go().push(AddMedicalPage());
  }

  @override
  void receiveMessage(SendMessageEvent event) {
    super.receiveMessage(event);
    if(event.msgCode==MessageConfig.FINISH_MEDICAL_SIGN){
      requestRefresh();
    }
  }
}